import Vue from 'vue'
import App from './App'

Vue.config.productionTip = false

App.mpType = 'app'

import uView from 'uview-ui'
Vue.use(uView)

Vue.prototype.$navigateBack = (router, delta) => {
	console.log('$navigateBack', router, delta)
	const pages = getCurrentPages()
	if (pages.length > delta) {
		console.log('uni.navigateBack', delta)
		uni.navigateBack({
			delta
		})
		return;
	}
	let a = router.go(-delta)
	if (a == undefined) {
		uni.reLaunch({
			url: "/pages/workOrder/workOrder"
		})
	}
	return;
}

function isPromise(obj) {
  return (
    !!obj &&
    (typeof obj === "object" || typeof obj === "function") &&
    typeof obj.then === "function"
  );
}

uni.addInterceptor({
  returnValue(res) {
    if (!isPromise(res)) {
      return res;
    }
    return new Promise((resolve, reject) => {
      res.then((res) => {
        if (res[0]) {
          reject(res[0]);
        } else {
          resolve(res[1]);
        }
      });
    });
  },
});

const app = new Vue({
  ...App
})
app.$mount()
